//本文件作者来自csdn https://blog.csdn.net/qq_39952971/article/details/130548647
//资源释放存在问题

#ifndef _SM2KA_H_
#define _SM2KA_H_

#include <openssl/evp.h>
#include <openssl/ec.h>
#include <openssl/ossl_typ.h>
#include <openssl/bn.h>
#include <openssl/err.h>
#include <openssl/crypto.h>
#include <openssl/obj_mac.h>
#include <openssl/asn1.h>
#include <openssl/asn1t.h>

typedef struct SM2KA_st {
	EC_GROUP *group;
	BN_CTX *ctx;
	BIGNUM *order;
	BIGNUM *r;
	BIGNUM *prik;
	EC_POINT *R;
	EC_POINT *P;
    unsigned char Z[32];

}SM2KA;

EC_POINT *agreement_init(SM2KA *ka, unsigned char *pri, unsigned char *pub_x, unsigned char *pub_y, unsigned char *id, int id_len);
EC_POINT *gen_agreementdata(SM2KA *ka);
EC_POINT *gen_agreementdata_key(SM2KA *ka, EC_POINT *RA, EC_POINT *PA, unsigned char *Z_peer);
int gen_key(SM2KA *ka, EC_POINT *RB, EC_POINT *PB, unsigned char *Z_peer);
void dump_point(SM2KA *ka, EC_POINT *P);
void dump_hex(const char *str, unsigned char *hex_data, int len);

#if 0
void SM2CS_init(SM2CS *cs);
void SM2CS_destrory(SM2CS *cs);

EC_POINT * getPubComponent(SM2CS *cs);
void getCommonPubk(SM2CS *cs, EC_POINT *Peer, EC_POINT **ComPubk, unsigned char *pub);

int signInitiator(SM2CS *cs, EC_POINT *Peer,EC_POINT **l_R,EC_POINT **l_Rt);
int signPartner(SM2CS *cs, EC_POINT *Peer, EC_POINT *R_peer,EC_POINT *Rt_peer,EC_POINT **l_R,EC_POINT **l_Rt);


int signInitiatorAgreement(SM2CS *cs, EC_POINT *R_peer,EC_POINT *Rt_peer,const unsigned char *E,BIGNUM *st);
//int signPartnerAgreement(SM2CS *cs, EC_POINT **QInitiator);
int signPartnerAgreement(SM2CS *cs, BIGNUM *st,BIGNUM *t);
int signInitiatorGetSign(SM2CS *cs, BIGNUM *t,BIGNUM *l_r ,BIGNUM *s);

#endif



#endif //_SM2KA_H_

